package com.admission.web;

import java.util.List;

import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.PropertyFilter;
import org.springside.modules.utils.web.struts2.Struts2Utils;

import com.admission.model.Special;
import com.admission.service.SpecialManager;
import com.admission.util.PageUtils;

@Namespace("/base")
@Results({ @Result(name = CrudActionSupport.RELOAD, location = "/base/index.action", type = "redirect") })
public class SpecialAction extends CrudActionSupport<Special> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4651984025146634092L;
	private Special entity;
	private SpecialManager specialManager;
	private String id;
	private Page<Special> page = new Page<Special>(PageUtils.DEFAULT_PAGE_SIZE);
	private String keyword;

	public Special getModel() {
		return entity;
	}

	@Override
	public String list() throws Exception {
		List<PropertyFilter> filtersSpecial = PropertyFilter
				.buildFromHttpRequest(Struts2Utils.getRequest());
		if (keyword != null) {
			PropertyFilter p = new PropertyFilter("LIKES_name", keyword);
			filtersSpecial.add(p);
		}
		page.setOrder(Page.DESC);
		page.setOrderBy("inputTime");
		page.setOrderBy("hightop");
		specialManager.getPage(page, filtersSpecial);
		return SUCCESS;
	}

	@Override
	public String input() throws Exception {
		return RELOAD;
	}

	/**
	 * 判断状态
	 * 
	 * @return
	 * @throws Exception
	 */
	public String checkConsult() throws Exception {
		if (specialManager.checkConsult().equals("1"))
			return list();
		return "fail";
	}

	@Override
	public String save() throws Exception {
		return RELOAD;
	}

	@Override
	public String delete() throws Exception {
		return RELOAD;
	}

	@Override
	protected void prepareModel() throws Exception {

	}

	public Special getEntity() {
		return entity;
	}

	public void setEntity(Special entity) {
		this.entity = entity;
	}

	public SpecialManager getSpecialManager() {
		return specialManager;
	}

	@Autowired
	public void setSpecialManager(SpecialManager specialManager) {
		this.specialManager = specialManager;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Page<Special> getPage() {
		return page;
	}

	public void setPage(Page<Special> page) {
		this.page = page;
	}

	public String getKeyword() {
		return keyword;
	}

	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}

}
